# overall

pdf("item_response_curves_overall.pdf", width = 11, height = 7)

b1 <- c(1.127, 1.197, 2.352, 1.194, 1.316, 2.339, 0.094)
b0 <- c(-2.712, -2.142, -.927, 0.535, 1.292, 1.728, -1.486)
names <- c("Nr of years experience", "Nr of years formal experience", "One prior political post", "Prior top post or ministry", "Two prior political posts", "Three prior political posts", "Nr of previous times in office")
fun <- c("linear", "linear", "logit", "logit", "logit", "logit", "linear")

plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 1), 
     xlab = "PolEx", ylab = "Pr(component)", bty = "n")

flin <- function(x, b0, b1) { b1 * (x - b0) }
flog <- function(x, b0, b1) { 1 / (1 + exp(-(b1 * (x - b0))))}

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] != "linear") {
    curve(flog(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")


plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 5.5), 
     xlab = "PolEx", ylab = "component", bty = "n")

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] == "linear") {
    curve(flin(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")

dev.off()




pdf("item_response_curves_democracies.pdf", width = 11, height = 7)

b1 <- c(0.877, 0.967, 1.749, 0.817, 1.260, 2.451, 0.110)
b0 <- c(-3.863, -3.090, -1.640, 0.694, 1.317, 1.664, -1.569)
names <- c("Nr of years experience", "Nr of years formal experience", "One prior political post", "Prior top post or ministry", "Two prior political posts", "Three prior political posts", "Nr of previous times in office")
fun <- c("linear", "linear", "logit", "logit", "logit", "logit", "linear")

plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 1), 
     xlab = "PolEx", ylab = "Pr(component)", bty = "n")

flin <- function(x, b0, b1) { b1 * (x - b0) }
flog <- function(x, b0, b1) { 1 / (1 + exp(-(b1 * (x - b0))))}

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] != "linear") {
    curve(flog(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")


plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 5.5), 
     xlab = "PolEx", ylab = "component", bty = "n")

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] == "linear") {
    curve(flin(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")

dev.off()





pdf("item_response_curves_autocracies.pdf", width = 11, height = 7)

b1 <- c(1.247, 1.248, 2.996, 2.015, 1.596, 2.424, 0.069)
b0 <- c(-2.122, -1.640, -0.430, 0.445, 1.208, 1.814, -1.400)
names <- c("Nr of years experience", "Nr of years formal experience", "One prior political post", "Prior top post or ministry", "Two prior political posts", "Three prior political posts", "Nr of previous times in office")
fun <- c("linear", "linear", "logit", "logit", "logit", "logit", "linear")

plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 1), 
     xlab = "PolEx", ylab = "Pr(component)", bty = "n")

flin <- function(x, b0, b1) { b1 * (x - b0) }
flog <- function(x, b0, b1) { 1 / (1 + exp(-(b1 * (x - b0))))}

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] != "linear") {
    curve(flog(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")


plot(0,0, type = "n", xlim = c(-2, 2), ylim = c(0, 5.5), 
     xlab = "PolEx", ylab = "component", bty = "n")

ltys <- NULL
labs <- NULL
cnt <- 1
for (i in 1:length(b1)) {
  
  if (fun[i] == "linear") {
    curve(flin(x, b0[i], b1[i]), add = TRUE, lwd = 2, lty = cnt)
    ltys <- c(ltys, cnt)
    labs <- c(labs, names[i])
    cnt <- cnt + 1
  }
}

legend("topleft", lty = ltys, lwd = 2, legend = labs, bty = "n")

dev.off()